package com.team.ssm_item_lj.controller;

import com.team.ssm_item_lj.entity.Devices;
import com.team.ssm_item_lj.service.DevicesService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

/**
 * 设备表(Devices)表控制层
 *
 * @author zhuxhenxin
 * @since 2024-12-05 10:44:29
 */
@RestController
@RequestMapping("devices")
public class DevicesController {
    /**
     * 服务对象
     */
    @Resource
    private DevicesService devicesService;

    /**
     * 分页查询
     *
     * @param devices 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Devices>> queryByPage(Devices devices, PageRequest pageRequest) {
        return ResponseEntity.ok(this.devicesService.queryByPage(devices, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Devices> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.devicesService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param devices 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Devices> add(Devices devices) {
        return ResponseEntity.ok(this.devicesService.insert(devices));
    }

    /**
     * 编辑数据
     *
     * @param devices 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Devices> edit(Devices devices) {
        return ResponseEntity.ok(this.devicesService.update(devices));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.devicesService.deleteById(id));
    }

}

